<template>
  <div>
    <div>
      <el-row>
        <el-col :span="20">
          <span>字典详情</span>
        </el-col>
        <el-col :span="4">
          <el-button
            type="primary"
            @click="dialogFormVisible = true"
            size="mini"
            >添加<i class="el-icon-upload el-icon--right"></i
          ></el-button>
          <el-dialog title="新增字典" :visible.sync="dialogFormVisible">
            <el-form :model="form">
              <el-form-item label="字典描述" :label-width="formLabelWidth">
                <el-input
                  v-model="tdictdescription"
                  autocomplete="off"
                  disabled="true"
                ></el-input>
              </el-form-item>
              <el-form-item label="字典标签" :label-width="formLabelWidth">
                <el-input v-model="form.label" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="字典值" :label-width="formLabelWidth">
                <el-input v-model="form.value" autocomplete="off"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible = false">取 消</el-button>
              <el-button type="primary" @click="bianji1">确 定</el-button>
            </div>
          </el-dialog>
        </el-col>
      </el-row>
    </div>
    <br /><br />
    <el-table :data="list" style="width: 100%">
      <el-table-column label="所属字典" width="150px" style="margin-left: 30px">
        <span>{{ dictvalue }}</span>
        <!-- <template slot-scope="scope">
                <span style="margin-left: 0px">{{ scope.row.dictId }}</span>
              </template> -->
      </el-table-column>
      <el-table-column label="字典标签" width="130px" style="margin-left: 10px">
        <template slot-scope="scope">
          <span style="margin-left: 0px">{{ scope.row.label }}</span>
        </template>
      </el-table-column>
      <el-table-column label="字典值" width="120px" style="margin-left: 10px">
        <template slot-scope="scope">
          <span style="margin-left: 0px">{{ scope.row.value }}</span>
        </template>
      </el-table-column>
      <el-table-column label="排序" width="180px" style="margin-left: 10px">
        <template slot-scope="scope">
          <span style="margin-left: 0px">{{ scope.row.dictSort }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit1(scope.row)"
            style="background-color: rgb(98, 166, 243)"
            ><i class="el-icon-edit" style="color: rgb(255, 255, 255)"></i
          ></el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete1(scope.row.id)"
            ><i class="el-icon-delete"></i
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :page-size="listQuery.pageSize"
        :page-sizes="[2, 4, 8]"
        :current-page.sync="listQuery.pageNum"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {
  dictdetaillist,
  dictidetailnsert,
  dictdetaildelet,
  dictdetailupdate,
} from "@/api/dict";
export default {
  // props:{row:Array},
  data() {
    return {
      operateType: null,
      listQuery: {
        keyword: null,
        nameCn: null,
        pageNum: 1,
        pageSize: 4,
        dictId: null,
      },
      list: null,
      total: null,
      listLoading: true,
      multipleSelection: [],
      lookup: null,
      cklook: false,
      dictvalue: null,
      form: {
        id: null,
        dictId: null,
        label: null,
        value: null,
        dictSort: null,
        createBy: null,
        updateBy: null,
        createTime: null,
        updateTime: null,
      },
      dialogFormVisible: false,
      formLabelWidth: "120px",
      tdictdescription: null,
      aa: null,
    };
  },
  created() {//接收父组件传递的参数
    this.$bus.$on("row", (dictlist) => {
      this.chax1(dictlist);
    });
  },
  methods: {
    onee() {//查询数据
      this.listLoading = true;
      dictdetaillist(this.listQuery).then((response) => {
        this.listLoading = false;
        this.list = response.data.records;
        this.total = response.data.total;
        this.totalPage = response.data.pages;
        this.pageSize = response.data.size;
      });
    },
    chax1(row) {
      //查询分页
      this.dictvalue = row.name;
      this.form.dictId = row.id;
      this.aa = row.id;
      this.listQuery.dictId = row.id;
      this.tdictdescription = row.description;
      this.onee();
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.chax();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.chax();
    },
    handleEdit1(row) {
      //编辑按钮弹出框
      this.form = row;
      this.dialogFormVisible = true;
    },
    handleDelete1(id) {
      //单个删除
      this.$confirm("确定删除他吗?", "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        dictdetaildelet(id).then((response) => {
          this.$message({
            message: "已经删除成功了哟！",
            type: "success",
            duration: 1000,
          });
          this.onee();
        });
      });
    },
    bianji1() {//做增加修改判断的
      if (this.form.id != null) {
        this.xiugai1();
        // this.onee();
      } else {
        this.tianj1();
        //  this.onee();
      }
    },
    qingchu1() {
        //格式化弹出表单的
      (this.form.id = null),
        (this.form.label = null),
        (this.form.value = null),
        (this.form.dictSort = null),
        (this.form.createBy = null),
        (this.form.updateBy = null),
        (this.form.createTime = null),
        (this.form.updateTime = null);
    },
    xiugai1() {
      //修改
      dictdetailupdate(this.form).then((response) => {
        this.dialogFormVisible = false;
        this.$message({
          message: "修改成功！",
          type: "success",
          duration: 1000,
        });
        this.qingchu1();
        this.onee();
      });
    },
    tianj1() {
      //右边添加
      dictidetailnsert(this.form).then((response) => {
        this.dialogFormVisible = false;
        this.$message({
          message: "添加成功！",
          type: "success",
          duration: 1000,
        });
        this.qingchu1();
        this.onee();
      });
    },
  },
};
</script>

<style>
</style>